# -*- coding: utf-8 -*-
# @Author  :   clumba
# @File    :   threadUtils.py
# @Time    :   2021/4/7 15:05


from concurrent.futures import ThreadPoolExecutor
import threading
import time

# 定义一个准备作为线程任务的函数
def action(max,min):
    time.sleep(5)
    # return max+min
# 创建一个包含2条线程的线程池
pool = ThreadPoolExecutor(max_workers=10)
# 向线程池提交一个task, 50会作为action()函数的参数


thread_list = []
for i in range(20):
    trd = pool.submit(action,i,i)
    thread_list.append(trd)
    print("thread %d added"%i)
print([i.result() for i in thread_list])
pool.shutdown()
print("ok")

#
#
# from concurrent.futures import ThreadPoolExecutor
# import threading
# import time
#
# # 定义一个准备作为线程任务的函数
# def action(max):
#     my_sum = 0
#     for i in range(max):
#         print(threading.current_thread().name + '  ' + str(i))
#         my_sum += i
#     return my_sum
# # 创建一个包含2条线程的线程池
# pool = ThreadPoolExecutor(max_workers=2)
# # 向线程池提交一个task, 50会作为action()函数的参数
# future1 = pool.submit(action, 50)
# # 向线程池再提交一个task, 100会作为action()函数的参数
# future2 = pool.submit(action, 100)
# # 判断future1代表的任务是否结束
# print(future1.done())
# time.sleep(3)
# # 判断future2代表的任务是否结束
# print(future2.done())
# # 查看future1代表的任务返回的结果
# print(future1.result())
# # 查看future2代表的任务返回的结果
# print(future2.result())
# # 关闭线程池
# pool.shutdown()
#


